define(function(require, exports, module){
	var actcont = require("oa/act/js/actcont.js");
	exports.load_view=function(processKey,processNodeId,bussId,taskId,tabId){
		var html="";
		//加载数据
		require.async ('resource/js/component/ajax.js',function(ajax){
			ajax.init().success(function(code,msg,datas){
				if(code==0){
					if(datas){
						var height=0;
						var mainHtml ="";
						if(datas.main&&datas.main.length>0){//加载form数据
							 mainHtml ="<ul class='list'>";
							var index=0;
							$.each(datas.main,function(i,main){
								var isMore="";
								var hangupuserid ="";
								if(main.hasOwnProperty("tab")){
									var tabs = main.tab;
									if(tabs.hasOwnProperty("ismore")){
										isMore = tabs.ismore;
									}
									if(tabs.hasOwnProperty("hangupuserid")){
										hangupuserid = tabs.hangupuserid;
									}
								}
								if(isMore==""){
									return;
								}
								if(hangupuserid!=""){//挂起人
									$("#hangUpUser").val(hangupuserid);
								}
								if(main.cols){
									if(isMore=="1"){//单行表单数据
										mainHtml = initFormData(main,mainHtml,i);
									}
								}
								index++;
							});
							mainHtml +="</ul><hr/>";
						}
						
						var subsHtml ="";
						if(datas.subs&&datas.subs.length>0){//加载form数据
							var index=0;
							$.each(datas.subs,function(i,subs){
								var isMore="";
								if(subs.hasOwnProperty("tab")){
									var tabs = subs.tab;
									if(tabs.hasOwnProperty("ismore")){
										isMore = tabs.ismore;
									}
								}
								if(isMore==""){
									return;
								}
								if(subs.cols){
									if(isMore=="1"){//单行表单数据
										//subsHtml+="<table class='list'>";
										subsHtml= initFormData(subs,subsHtml,i)+'<hr/>';
										//subsHtml +="</table>";
									}else{//多行表格数据
										subsHtml+=initTableData(subs)+'<hr/>';
									}
								}
								index++;
							});
							
						}
						$("#"+tabId).html(mainHtml+subsHtml);
						addFileEvent();
					}
				}
			}).post(BASEPATH+"/oa/act/actProgressTable/queryBussInfo.htm",{processKey:processKey,processNodeId:processNodeId,bussId:bussId,taskId:taskId}
			);
		});
		loadCCUsers(bussId);
	}
	function initFormData(main,html,num){
		var len = main.cols.length;
		var col_idex = 0;
		var ind = 0;
		if(num!=undefined&&num!=null){
			ind=num;
		}
		$.each(main.cols,function(i,col){
			var show =  !(col.showtype==actcont.showType.FORM_SHOWTYPE_HIDDEN);
			show = main.data && main.data.length > 0 && main.data[0];
			if (col_idex == 0) {
				html += "<li"+(show?"":" style='display:none'")+">";
			} else {
				html += "</li><li"+(show?"":" style='display:none'")+">";
			}
			var colId =col.colname;
			//隐藏域处理//
			if (col.showtype==actcont.showType.FORM_SHOWTYPE_HIDDEN){
			//多行文本处理//
			}else if (col.showtype==actcont.showType.FORM_SHOWTYPE_TEXTAREA) {
				html+='<span class="col-name">'+col.colnamech+'：</span><span class="col-val">'+((main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined)?main.data[ind][''+colId+'']:"")+'</span>';
			//其他//
			}else if(col.showtype==actcont.showType.FORM_SHOWTYPE_FILE){
				html+='<span class="col-name">'+col.colnamech+'：</span>';
				if(main.data!=null&&main.data.length>0&&main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined&&main.data[ind][''+colId+'']!=""&&main.dataaddon != null){
					var files = main.dataaddon[''+colId+''];
					if(files&&files.length>0){
						var fileDownload='<div class="fileList col-val">';
						for(var i=0;i<files.length;i++){
							var file = files[i];
							var fileUrl = file.fileUrl;
							var fileName = file.fileName+"."+file.fileExt;
							//var size = getFileSize(file.fileSize);
							var icon = getFileIcon(file.fileExt);
							//fileDownload +="<a href='javascript:window.open (\""+BASEPATH+fileUrl+"\")'>"+fileName+"</a>&nbsp;&nbsp;";
							fileDownload += '<div class="fileSet" data-url='+fileUrl+'>'
			   					+ '<div class="'+icon+'">'
			   						+'<p style="margin-bottom:0;color:#333;">'+fileName+'</p>'
			   						/*+'<p class="prompt" style="margin-bottom:0;">'+size+'</p>'*/
		   						+'</div></div>';
						}
						html += fileDownload;
					}
				}	
			}else{
				html+='<span class="col-name">'+col.colnamech+'：</span><span class="col-val">'+((main.data[ind]!=null&&main.data[ind][''+colId+'']!=undefined)?main.data[ind][''+colId+'']:"")+'</span>';
			}
		});
		//return  html+"</tr>";
		return  html
	}
	function addFileEvent(){
		$(".fileList .fileSet").bind('click',function(){
			var url = $(this).data('url');
			url&&window.open (BASEPATH+url);
		});
	}
	function initTableData(subs,num){
		//封装表格列 数据
		var columnsList =[];
		var tabHtml="";
		if(subs.cols&&subs.cols.length>0){
			 var tabName=subs.tab.tablekey;
			if(subs.data&&subs.data.length>0){
				$.each(subs.data,function(i,data){
					 tabHtml+= "<ul class='list marginBottom10'><caption><div class='sub-title'>"+subs.tab.tablename+"明细(<span>"+(i+1)+"</span>)</div><caption>";
					 tabHtml=initFormData(subs,tabHtml,i); 
					 tabHtml+="</ul>";
				});
			}
		}
		return tabHtml;
	}
	function getFileSize (size){
		var result = size < 1024 ? size.toFixed(2)+'B' 
   				: size < (1024*1024) ? (size/1024).toFixed(2)+'KB'
				:(size/(1024*1024)).toFixed(2)+'MB';
   		return result;
	}
	function getFileIcon(ext){
		var iconClass='';
		if(/^(gif|png|jpg|jpeg|bmp)$/i.test(ext)){
			iconClass = 'pictureIcon';
		}else if(/^(mp3|mp4|avi|dat|mkv|flv)$/i.test(ext)){
			iconClass = 'mediaIcon';
		}else{
			iconClass = 'fileIcon';
		}
		return iconClass;
	}
	/**
	 * 加载抄送人
	 */
	function loadCCUsers(businessId){
		if(businessId){
			//加载数据
			require.async ('resource/js/component/ajax.js',function(ajax){
				ajax.init().success(function(code,msg,datas){
					if(datas!=null&&datas.length>0){
						var colors = ['#229af9','#e91e63','#ffc107','#8bc34a','#3f51b5','#00bcd4'];
						var html="";
						$.each(datas,function(i,val){
						   var text = val.userName.substring(0,1);
						   var col_index = i%colors.length;
						   html += "<div class='approvers-item'>" +
									"<div  class='approvers-item-person person-delete' style='background-color: "+colors[col_index]+"' title='点击移除 '>" +
									"<span class='name-first'>"+text+"</span>" +
									"</div>" +
									"<div class='personName'>"+val.userName+"</div>" +
								"</div>";
					   });
						$("#copyUser").html(html);
						$("#copyUsers").show();

					}else{
						$("#copyUsers").hide();
					}
				}).post(BASEPATH+"/oa/actCC/queryCCUsers.htm",{businessId:businessId});
			});	
		}			
	}

})